<?php
class itemscollection extends daocollection implements daocollectioninterface
{
	
	private $condition = 1;
	
	public function __construct(dao $currentitem)
	{
		$this->currentitem = $currentitem;
	}
	
	public function getwithdata($start = NULL, $pagesize = 10)
	{
		$connection = db::factory('mysql');
		
		if(is_null($this->currentitem->type)){
			$sql = "SELECT * FROM Items	ORDER BY id DESC ";
		}else{
			$sql = "SELECT * FROM Items WHERE type={$this->currentitem->type} ORDER BY id DESC ";
		}
		
		if(is_numeric($start)){
			$sql .= "LIMIT $start, $pagesize";
		}
		
		$results = $connection->getArray($sql);
		
		$this->populate($results, 'item');
	}
	
	public function getcount()
	{
		$connection = db::factory('mysql');
		
		if(is_null($this->currentitem->type)){
			$sql = "SELECT count(*) FROM Items WHERE " . $this->condition;
		}else{
			$sql = "SELECT count(*) FROM Items WHERE type={$this->currentitem->type} AND " . $this->condition;
		}
		
		$results = $connection->getArray($sql);
		
		return $results[0]['count(*)']; 
	}
	
	public function setkey()
	{
		
	}
	
	public function search($condition = NULL)
	{
		
	}
}